<?php
// No direct access
defined ('_JEXEC') or die();

jimport ('joomla.application.component.controllerform');
jimport ('joomla.user.helper');

class ShipnhanhControllerOrder extends JControllerForm
{
	public function getModel($name = '', $prefix = '', $config = array('ignore_request' => true))
	{
		return parent::getModel($name, $prefix, array('ignore_request' => false));
	}
	
	public function submit()
	{
		// Check for request forgeries
		JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
		
		$model = $this->getModel('Order');
		$data = JRequest::getVar('jform', array(), 'post', 'array');
		
		$success = $model->insertOrder($data);
		
		if ($success)
		{
			// redirect to success page
			$app = JFactory::getApplication();
			$user = JFactory::getUser();
			$app->setUserState($user->id . '.data', $data);
			$link = JRoute::_('index.php?option=' . $this->option . '&layout=success');
			$this->setRedirect($link);
		}
		else
		{
			// redirect to failed page
			JError::raiseError(500, JText::_('COM_SHIPNHANH_500_ERROR'));
		}
		
		return true;
	}
}